import {useEffect} from 'react';
import {BackHandler} from 'react-native';

/**
 * 物理返回键处理hook
 * @param handler
 */
const useBackHandler = (handler: () => boolean) => {
  useEffect(() => {
    BackHandler.addEventListener('hardwareBackPress', handler);

    return () => BackHandler.removeEventListener('hardwareBackPress', handler);
  }, [handler]);
};

export default useBackHandler;
